<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
/***************************
傳進參數
GambleID：操盤序號
Bet_Type：下注種類
OddsID：賠率序號
Odds：賠率值
LottoID：樂透種類序號
Number：號碼
StakeMoney：下注金額
CheckKey1+CheckKey2：檢查鍵值(防止下注重複)
ChoiceNumber：選擇號碼組
***************************/
include_once("../config.inc.php");

session_start();
$objMemberInfo = $_SESSION["Member_Info"];

$_LangPath = "wagerinsert";	//語言檔參數，務必放在最前面
//補貨方式
if($objMemberInfo -> SuppleID == "" && $objMemberInfo -> WagerType == 0)include_once(__Member_Path."/logincheck.php");
include(__Language_Path."/selectlanguage_member.php");
include_once(__Modules_Path."/Wager.lib.php");
include_once(__Modules_Path."/WagerForm.lib.php");
include_once(__Common_Path."/Lotto.inc.php");
include_once(__Common_Path."/ExchangeRate.inc.php");
include_once(__Modules_Path."/LogRecord.lib.php");
include_once(__Modules_Path."/Odds.lib.php");
include_once(__Modules_Path."/joinnumber.lib.php");
if($objMemberInfo -> isLock == '2'){
	$GLOBALS["errormessage"] = $_strStopWager;
	include("wager_error.php");
}

$intLID = (int)$_data["LottoID"];
$intGID = (int)$_data["GambleID"];
$intLType = (int)$_arrLotto[$intLID]["LType"];
$intBT = (int)$_data["Bet_Type"];
$intNum = (int)$_data["Number"];
$intOddsID = (int)$_data["OddsID"];
$flOdds = (float)$_data["Odds"];
$intStakeMoney = (int)$_data["StakeMoney"];
$_data["CheckKey1"] = trim($_data["CheckKey1"]);
$_data["CheckKey2"] = trim($_data["CheckKey2"]);

//找出 Apoint
$intAN = (int)$_arrGLineNumToApointNum[$intLID][$intBT][$intNumber];

$arrChoiceNumber = split(",", $_data["ChoiceNumber"]);

if(__isConnectToOtherWeb == 1){
	$flMemERate = (empty($objMemberInfo -> ExRate))?1:$objMemberInfo -> ExRate;
}else{
	$flMemERate = (empty($_ECRate[$objMemberInfo -> ERID]["Rate"]))?1:$_ECRate[$objMemberInfo -> ERID]["Rate"];
}

//檢查關鍵參數是否為空值
if(!$intLID || !$intLType || empty($intBT) || empty($_data["CheckKey2"]) || empty($_data["CheckKey1"]) || empty($intOddsID) || empty($intStakeMoney) || empty($intGID) || strlen($_data["Number"]) == 0 || ($intBT == 30 && sizeof($arrChoiceNumber) != 6)){
	$Err_Title = $_strWagerInsert["BetError"];
	$Err_Message = $_strWagerInsert["BetAgain"];
	$Err_HiddenMessage = "\nLine:".__LINE__.",\nPage:".__FILE__;
	include("wager_error.php");
}
//檢查下注金額是否為數值
/*if(!ereg("^[0-9]{0,7}$", $intStakeMoney)){
	$Err_Title = $_strWagerInsert["BetError"];
	$Err_Message = $_strWagerInsert["StakeisString"];
	$Err_HiddenMessage = "\nLine:".__LINE__.",\nPage:".__FILE__;
	include("wager_error.php");
}*/

//不正確下注模式
$arrTmpBT[1] = array(1,2,3,4,5,6,12,13,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29);
$arrTmpBT[2] = array(51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93);
$arrTmpBT[3] = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22);
$arrTmpBT[4] = array(1,2,3,4,5,6,7,8,9,10,11,12,13,29);
$arrPermitBT = $arrTmpBT[$intLType]; //允許下注種類
if(!in_array($intBT, $arrPermitBT)){
	$Err_Title = $_strWagerInsert["BetError"];
	$Err_Message = $_strWagerInsert["ErrBetType"];
	$Err_HiddenMessage = "\nLine:".__LINE__.",\nPage:".__FILE__;
	include("wager_error.php");
}

if($intLType == 1){
	if($intBT == 28 && $_KSysParam[isOpenSpecialNumberBLine] != 1){
		$Err_Title = $_strWagerInsert["BetError"];
		$Err_Message = $_strWagerInsert["ErrBetType"];
		$Err_HiddenMessage = "\nLine:".__LINE__.",\nPage:".__FILE__;
		include("wager_error.php");
	}
}

//賠率轉換值
$flCommOddsPlus = 0;
$isAcceptLimit = false;
if($intLID == 4){
	include_once(__Common_Path."/CommToOddsRate_".$intLID.".inc.php");
	include_once(__Modules_Path."/Commission.lib.php");
	//找出 使用者 的賠率兌換，傳回陣列
	$arrUserOPlus = getUserCommToOdds($objMemberInfo -> ID, $intLID, array($intBT));
	if($arrUserOPlus === false)ErrMsgOutputHTML("Error", "", 1);
	$flCommOddsPlus = $arrUserOPlus[$intBT][$intAN][11] * $_arrChRate[$intBT][$intAN][$objMemberInfo -> GambleType+10];
	$flCommPlus = $arrUserOPlus[$intBT][$intAN][11] * 1;
	if($intBT >= 7 && $intBT <= 11)$isAcceptLimit = true;
}

$isUseJoinNumberLimit = false;

switch($intLType.'_'.$intBT){
	case '2_78':
	case '2_79':
	case '2_80':
	case '2_81':
	case '2_82':
	case '2_83':
		$isUseJoinNumberLimit = true;
		$intStNumber = $intBT - 75;
		$arrCNTmp = $arrChoiceNumber;
		$strJoinNumber = "";
		$strChoiceNumber = "";
		foreach($arrCNTmp as $k => $strCNTmp){
			$strT = chr(67 - $k);
			$arrCN = split("x", $strCNTmp);
			sort($arrCN);
			foreach($arrCN as $k2 => $strCN){
				$arrCN[$k2] = (int)$strCN; //將數值都轉化為整數
				if($arrCN[$k2] > 9 || $arrCN[$k2] < 0){	//若數值不再 0~9 之間都是錯誤
					$Err_Title = $_strWagerInsert["BetError"];
					$Err_Message = $_strWagerInsert["SelectNumberErr"];
					$Err_HiddenMessage = "\nStNumber:".print_r($arrChoiceNumber, true)."\nLine:".__LINE__.",\nPage:".__FILE__;
					include("wager_error.php");
				}
			}
			$arrChoiceNumber[$k] = $arrCN;
			$strJoinNumber .= $strT.join($strT, $arrCN)."-";
			$strChoiceNumber .= join("x", $arrCN).",";
		}
		$arrWCont["JoinNumber_x"] = substr($strJoinNumber, 0, -1);
		$_data["ChoiceNumber"] = substr($strChoiceNumber, 0, -1);

		if($intBT != 83){
			//檢查號碼組數是否正確
			if(sizeof($arrChoiceNumber[0]) != $intStNumber && sizeof($arrChoiceNumber[1]) != $intStNumber && sizeof($arrChoiceNumber[2]) != $intStNumber){
				$Err_Title = $_strWagerInsert["BetError"];
				$Err_Message = $_strWagerInsert["SelectNumberErr"];
				$Err_HiddenMessage = "\nStNumber:".print_r($arrChoiceNumber, true)."\nLine:".__LINE__.",\nPage:".__FILE__;
				include("wager_error.php");
			}
		}else{
			$intTotalCNo = sizeof($arrChoiceNumber[0]) + sizeof($arrChoiceNumber[1]) + sizeof($arrChoiceNumber[2]);
			//檢查號碼組數是否正確
			if(sizeof($arrChoiceNumber[0]) == 0 || sizeof($arrChoiceNumber[1]) == 0 || sizeof($arrChoiceNumber[2])  == 0 || $intTotalCNo < 8 || $intTotalCNo > 21){
				$Err_Title = $_strWagerInsert["BetError"];
				$Err_Message = $_strWagerInsert["SelectNumberErr"];
				$Err_HiddenMessage = "\nStNumber:".print_r($arrChoiceNumber, true)."\nLine:".__LINE__.",\nPage:".__FILE__;
				include("wager_error.php");
			}
		}
		break;
	
	case '1_30':
		$arrTmp = array();
		sort($arrChoiceNumber);
		foreach($arrChoiceNumber as $k => $strCN){
			$intCN = (int)$strCN;
			$arrChoiceNumber[$k] = $intCN;
			//所選擇，不能超出規定
			if($intCN > 12 || $intCN < 1){
				$Err_Title = $_strWagerInsert["BetError"];
				$Err_Message = $_strWagerInsert["SelectNumberErr"];
				$Err_HiddenMessage = "\nStNumber:".print_r($arrChoiceNumber, true)."\nLine:".__LINE__.",\nPage:".__FILE__;
				include("wager_error.php");
			}
			$arrTmp[$intCN] = 1;	//消除重複號碼
			$strChoiceNumber .= ($intCN < 10)?("0".(string)$intCN.","):((string)$intCN.",");
		} //foreach($arrChoiceNumber as $strCN){

		if(sizeof($arrTmp) != 6){ //若消除重複號碼後，若組數不等於 6組，視為錯誤
			$Err_Title = $_strWagerInsert["BetError"];
			$Err_Message = $_strWagerInsert["SelectNumberErr"];
			$Err_HiddenMessage = "\nStNumber:".print_r($arrChoiceNumber, true)."\nLine:".__LINE__.",\nPage:".__FILE__;
			include("wager_error.php");
		}
		$arrWCont["JoinNumber_x"] = substr($strChoiceNumber, 0, -1);
		$_data["ChoiceNumber"] = $arrWCont["JoinNumber_x"];
		break;

	default:
		$arrStNumber = array( 2 => array(69 => 5, 70 => 6, 71 => 7, 72 => 8, 73 => 4, 74 => 5, 75 => 6, 76 => 7, 77 => 8) );
		$arrGroupCounter = array(	2 => array(69 => 2, 70 => 2, 71 => 2, 72 => 2, 73 => 3, 74 => 3, 75 => 3, 76 => 3, 77 => 3)	);

		if($arrStNumber[$intLType][$intBT] > 0){
			$intMinN = 0;
			$intMaxN = 9;

			$intStNumber = $arrStNumber[$intLType][$intBT];
			$arrCNTmp = array();
			$arrTmp = array();
			foreach($arrChoiceNumber as $key => $strCN){
				$intCN = (int)$strCN;
				$arrChoiceNumber[$key] = (int)$strCN;	//將數值都轉化為整數
				if($arrChoiceNumber[$key] > $intMaxN || $arrChoiceNumber[$key] < $intMinN){	//若數值不再 0~9 之間都是錯誤
					$Err_Title = $_strWagerInsert["BetError"];
					$Err_Message = $_strWagerInsert["SelectNumberErr"];
					$Err_HiddenMessage = "\nStNumber:".print_r($arrChoiceNumber, true)."\nLine:".__LINE__.",\nPage:".__FILE__;
					include("wager_error.php");
				}
				$arrTmp[$intCN] = 1;	//消除重複號碼
			}
			if(sizeof($arrTmp) != $intStNumber){
				$Err_Title = $_strWagerInsert["BetError"];
				$Err_Message = $_strWagerInsert["SelectNumberErr"];
				$Err_HiddenMessage = "\nStNumber:".print_r($arrChoiceNumber, true)."\nLine:".__LINE__.",\nPage:".__FILE__;
				include("wager_error.php");
			}
			$arrWCont["JoinNumber_x"] = join(",", $arrChoiceNumber);
			$_data["ChoiceNumber"] = $arrWCont["JoinNumber_x"];

			//取得下注總組數，steve 需要資料
			$arrChoiceNumGroup = getCombination($arrChoiceNumber, $arrGroupCounter[$intLType][$intBT]);
			//print_r($arrChoiceNumGroup);
			//print_r($arrChoiceNumber);
			//print implode(", ", getCombination(array(0, 1, 2, 3, 4,5 , 6, 7, 8, 9), 3));

		}else{ //if($arrStNumber[$intLType][$intBT] > 0){
			$arrChoiceNumber = null;
		} //if($arrStNumber[$intLType][$intBT] > 0){
		break;
} //switch($intBT)

//會員、代理商、總代理、股東退水質不得為空值
foreach($objMemberInfo -> arrCommission as $intGroup => $arrC){
	$arrComm[$intGroup] = $arrC[$intLID][$intBT];
	if( empty($arrComm[$intGroup]) ){
		$Err_Title = $_strWagerInsert["BetError"];
		$Err_Message = $_strWagerInsert["CommissionErr"];
		$Err_HiddenMessage = "\nLine:".__LINE__.",\nPage:".__FILE__;
		include("wager_error.php");
	}
}

include_once(__Common_Path."/limit/LottoLimit_".$intLID.".inc.php");
include_once(__Common_Path."/betparam/BetParam_".$intLID.".inc.php");
if(!is_array($_arrBetParam[$intBT][$intAN])){
	$Err_Message = "No Wager Relation Data!!";
	include("wager_error.php");
}
//判斷是否啟動自動向上補貨
$isAutoSupple = false;
if(($objMemberInfo -> SubIsAutoSupple || $objMemberInfo -> MainIsAutoSupple || $objMemberInfo -> StockIsAutoSupple || $objMemberInfo -> DirectorIsAutoSupple || $objMemberInfo -> Layer6IsAutoSupple)){//$intLID == 1 && 
	if($intLID == 1 && $intBT == 28){
		if($_arrBetParam[1][$intAN]["isAutoSupple"])$isAutoSupple = true;
	}else{
		if($_arrBetParam[$intBT][$intAN]["isAutoSupple"])$isAutoSupple = true;
	}
}

//===========================================================================//
//判斷最小單注或單場限額
$BetLimit = $objMemberInfo -> arrBetLimit[$intLID][$intBT];
$EventLimit = $objMemberInfo -> arrEventLimit[$intLID][$intBT];
if($_arrLottoLimit[$intBT][0] > 0){
	$_arrLottoLimit[$intBT][0] = floor($_arrLottoLimit[$intBT][0] / $flMemERate);
	if($_arrLottoLimit[$intBT][0] < $EventLimit)$EventLimit = $_arrLottoLimit[$intBT][0];
}
if($_arrLottoLimit[$intBT][1] > 0){
	$_arrLottoLimit[$intBT][1] = floor($_arrLottoLimit[$intBT][1] / $flMemERate);
	if($_arrLottoLimit[$intBT][1] < $BetLimit)$BetLimit = $_arrLottoLimit[$intBT][1];
}
//公司單注限額
$Com_BetLimit = floor($_arrBetParam[$intBT][$intAN]["Com_BetLimit"] / ($objMemberInfo -> Layer6Scale*$flMemERate));
if($Com_BetLimit < $BetLimit)$BetLimit = $Com_BetLimit;

$intMinStake = floor($_arrBetParam[$intBT][$intAN]["MinStake"] / $flMemERate);
//下注金額不能小於最小下注金額
if($intStakeMoney < $intMinStake){
	$Err_Title = $_strWagerInsert["BetError"];
	$Err_Message = $_strWagerInsert["NotUnderMinStake"]."(".number_format($intMinStake).")";
	$Err_HiddenMessage = "\nLine:".__LINE__.",\nPage:".__FILE__;
	include("wager_error.php");
}
//下注金額不能大於單注限額
if($intStakeMoney > $BetLimit){
	$Err_Title = $_strWagerInsert["BetError"];
	$Err_Message = $_strWagerInsert["NotOverMaxStake"]."(".number_format($BetLimit).")";
	$Err_HiddenMessage = "\nLine:".__LINE__.",\nPage:".__FILE__;
	include("wager_error.php");
}

//===========================================================================//
/*include_once(__Modules_Path."/RealBet.lib.php");
//是否上層停押
$strParentID = $objMemberInfo -> SubID.",".$objMemberInfo -> MainID.",".$objMemberInfo -> StockID;
if(!$strTop = GetOneStopWagerBet($intGID, $intBT, $intNum, $strParentID)){
	$Err_Message = $GLOBALS["errormessage"];
	$Err_HiddenMessage = $GLOBALS["errorhidden"];
	include("wager_error.php");
}
if($strTop == "Stop"){
	$Err_Message = $_strWagerInsert["StopWager"];
	include("wager_error.php");
}*/

//===========================================================================//
//交易開始
$arrLayerID = array(2 => $objMemberInfo -> SubID, 3 => $objMemberInfo -> MainID, 4 => $objMemberInfo -> StockID, 5 => $objMemberInfo -> DirectorID, 6 => $objMemberInfo -> Layer6ID);

PMA_mysql_query("BEGIN", $_ConnMaster);
//下注額度不能大於上層可接收注額
if($isAcceptLimit || $isAutoSupple){
	//取得各階層的下注額度
	$arrRealStake = getUserUpLayerRealStake($intLID, $intGID, array($intBT), array($intNum), $arrLayerID);
	if($arrRealStake === false){
		PMA_mysql_query("ROLLBACK", $_ConnMaster);
		$Err_Message = ($_strWagerInsert[$GLOBALS["errormessage"]] != "")?$_strWagerInsert[$GLOBALS["errormessage"]]:$GLOBALS["errormessage"];
		$Err_HiddenMessage = $GLOBALS["errorhidden"];
		include("wager_error.php");
	}
	//print_r($arrRealStake);

	$arrAcceptLimit = $objMemberInfo -> arrAcceptLimit[$intLID][$intBT];
	$arrAutoSuppleLimit = ($intLID == 1 && $intBT == 28)?$objMemberInfo -> arrAutoSuppleLimit[$intLID][1]:$objMemberInfo -> arrAutoSuppleLimit[$intLID][$intBT];

	$arrAutoSuppleGold = array();
	$arrAutoSuppleGroup = array();
	foreach($arrLayerID as $intGroup => $intUID){
		if($intUID == $objMemberInfo -> ID){
			if($intStakeMoney > $arrRealStake[$intBT][$intNum][$intUID]){
				$Err_Message = "Over Credit Data";
				include("wager_error.php");
			}
			continue;
		}
		if(!$isAutoSupple && $isAcceptLimit && (float)$arrAcceptLimit[$intUID] <= 0)continue;
		//if($arrAutoSuppleLimit[$intUID] < 0)$arrAutoSuppleLimit[$intUID] = 0;

		$flRealStake = 0;
		$isLayerAutoSupple = false;
		$arrAutoSuppleGroupGold[$intGroup] = 0; //各階層自動補貨金額
		switch($intGroup){
			case 2:
				$flRealStake = $flMemERate*$intStakeMoney*(1 - $objMemberInfo -> SubScale);
				$isLayerAutoSupple = $objMemberInfo -> SubIsAutoSupple;
				break;

			case 3:
				$flRealStake = $flMemERate*$intStakeMoney*($objMemberInfo -> SubScale - $objMemberInfo -> MainScale);
				$flRealStake += $arrAutoSuppleGroupGold[2]*($objMemberInfo -> SubScale - $objMemberInfo -> MainScale);
				$isLayerAutoSupple = $objMemberInfo -> MainIsAutoSupple;
				break;

			case 4:
				$flRealStake = $flMemERate*$intStakeMoney*($objMemberInfo -> MainScale - $objMemberInfo -> StockScale);
				$flRealStake += ($arrAutoSuppleGroupGold[2] + $arrAutoSuppleGroupGold[3])*($objMemberInfo -> MainScale - $objMemberInfo -> StockScale);

				$isLayerAutoSupple = $objMemberInfo -> StockIsAutoSupple;
				//print "==".$objMemberInfo -> StockIsAutoSupple."==";
				break;

			case 5:
				$flRealStake = $flMemERate*$intStakeMoney*($objMemberInfo -> StockScale - $objMemberInfo -> DirectorScale);
				//$flRealStake += ($arrAutoSuppleGroupGold[2] + $arrAutoSuppleGroupGold[3] + $arrAutoSuppleGroupGold[4])*($objMemberInfo -> StockScale - $objMemberInfo -> DirectorScale);
				$flRealStake += $arrAutoSuppleGroupGold[2]*($objMemberInfo -> LayerScale[2][4] - $objMemberInfo -> LayerScale[2][5]) + $arrAutoSuppleGroupGold[3]*($objMemberInfo -> LayerScale[3][4] - $objMemberInfo -> LayerScale[3][5]) + $arrAutoSuppleGroupGold[4]*($objMemberInfo -> LayerScale[4][4] - $objMemberInfo -> LayerScale[4][5]);

				$isLayerAutoSupple = $objMemberInfo -> DirectorIsAutoSupple;
				break;

			case 6:
				$flRealStake = $flMemERate*$intStakeMoney*($objMemberInfo -> DirectorScale - $objMemberInfo -> Layer6Scale);
				$flRealStake += $arrAutoSuppleGroupGold[2]*($objMemberInfo -> LayerScale[2][5] - $objMemberInfo -> LayerScale[2][6]) + $arrAutoSuppleGroupGold[3]*($objMemberInfo -> LayerScale[3][5] - $objMemberInfo -> LayerScale[3][6]) + $arrAutoSuppleGroupGold[4]*($objMemberInfo -> LayerScale[4][5] - $objMemberInfo -> LayerScale[4][6]) + $arrAutoSuppleGroupGold[5]*($objMemberInfo -> LayerScale[5][5] - $objMemberInfo -> LayerScale[5][6]);

				$isLayerAutoSupple = $objMemberInfo -> Layer6IsAutoSupple;
				break;
		}
		if($isAcceptLimit && $arrAcceptLimit[$intUID] > 0 && $arrRealStake[$intBT][$intNum][$intUID] + $flRealStake > $arrAcceptLimit[$intUID]){
			PMA_mysql_query("ROLLBACK", $_ConnMaster);
			if($GLOBALS["errormessage"] == "")$Err_Message = $_strWagerInsert["NotOverAccept"];
			$Err_Title = $_strWagerInsert["BetError"];
			$Err_HiddenMessage = "\nLine:".__LINE__.",\nPage:".__FILE__;
			include("wager_error.php");
		}

		if($isLayerAutoSupple){
			//print "Auto<br />";
			//print $intUID." = ".$_arrBetParam[$intBT]["AutoSuppleOverGold"]." + ".$arrAutoSuppleLimit[$intUID]." <.". $arrRealStake[$intBT][$intNum][$intUID]." + ".$flRealStake;
			if($arrAutoSuppleLimit[$intUID] < 0 || $arrAutoSuppleLimit[$intUID] == null)continue;//$arrAutoSuppleLimit[$intUID] = 0;

			$intBTTmp = $intBT;
			if($intLID == 1 && $intBTTmp == 28)$intBTTmp = 1;

			//print $_arrBetParam[$intBTTmp]["isAutoSupple"]."==".$intUID." = ".$_arrBetParam[$intBTTmp]["AutoSuppleOverGold"]." + ".$arrAutoSuppleLimit[$intUID]." <.". $arrRealStake[$intBTTmp][$intNum][$intUID]." + ".$flRealStake;
			if($_arrBetParam[$intBTTmp][$intAN]["isAutoSupple"] == 1 && ($_arrBetParam[$intBTTmp][$intAN]["AutoSuppleOverGold"] + $arrAutoSuppleLimit[$intUID]) <= ($arrRealStake[$intBTTmp][$intNum][$intUID] + $flRealStake)){
				$arrAutoSuppleGold[$intUID] = $arrRealStake[$intBTTmp][$intNum][$intUID] + $flRealStake - $arrAutoSuppleLimit[$intUID];
				$arrAutoSuppleGroup[$intUID] = $intGroup;
				$arrAutoSuppleGroupGold[$intGroup] = $arrAutoSuppleGold[$intUID];
			}
		}
	}
}
//print_r($arrAutoSuppleGold);
//print_r($arrAutoSuppleGroup);
//print_r($arrAutoSuppleGroupGold);
//print_r($arrLayerID);
//exit();

$_arrMemStake = getWagerArrayGoldByDB($objMemberInfo -> ID, $objMemberInfo -> WagerType);
if($_arrMemStake === false){
	PMA_mysql_query("ROLLBACK", $_ConnMaster);
	$Err_Message = ($_strWagerInsert[$GLOBALS["errormessage"]] != "")?$_strWagerInsert[$GLOBALS["errormessage"]]:$GLOBALS["errormessage"];
	$Err_HiddenMessage = $GLOBALS["errorhidden"];
	include("wager_error.php");
}
$intEvent = $_arrMemStake[$intBT][$intGID][$intNum];

if($isUseJoinNumberLimit){	//限額採用另外計算方式
	$intEvent = getWagerLimitGoldByJoinNumber($objMemberInfo -> ID, $intGID, $intBT, $arrWCont["JoinNumber_x"], $objMemberInfo -> WagerType);
	if($intEvent === false){
		PMA_mysql_query("ROLLBACK", $_ConnMaster);
		$Err_Message = ($_strWagerInsert[$GLOBALS["errormessage"]] != "")?$_strWagerInsert[$GLOBALS["errormessage"]]:$GLOBALS["errormessage"];
		$Err_HiddenMessage = $GLOBALS["errorhidden"];
		include("wager_error.php");
	}
	//print $intEvent;
}

//下注金額不能大於單場限額
if($intStakeMoney > ($EventLimit - $intEvent)){
	PMA_mysql_query("ROLLBACK", $_ConnMaster);
	$Err_Title = $_strWagerInsert["BetError"];
	$Err_Message = $_strWagerInsert["NotOverEvenLimit"];
	$Err_Message .= $_strWagerInsert["EvenLimit"]."(".number_format($EventLimit).")<br>";
	$Err_Message .= $_strWagerInsert["ThisStake"]."(".number_format($intEvent).")";
	$Err_HiddenMessage = "\nLine:".__LINE__.",\nPage:".__FILE__;
	include("wager_error.php");
}
//下注金額不能大於信額額度
$intSum = ($objMemberInfo -> WagerType == 0)?$_arrMemStake["_SUM"]:$intEvent;
if($intStakeMoney > ($objMemberInfo -> CreditLine - $intSum)){
	PMA_mysql_query("ROLLBACK", $_ConnMaster);
	$Err_Title = $_strWagerInsert["BetError"];
	$Err_Message = $_strWagerInsert["NotOverCredit"];
	$Err_Message .= $_strWagerInsert["MemCredit"]."(".number_format($objMemberInfo -> CreditLine).")<br>";
	$Err_Message .= $_strWagerInsert["UsedCredit"]."(".number_format($intSum).")";
	$Err_HiddenMessage = "\nLine:".__LINE__.",\nPage:".__FILE__;
	include("wager_error.php");
}
//下注金額不能大於上層信額額度
if($objMemberInfo -> WagerType == 0){	//正式注單
	if(isOverParentCredit($intStakeMoney*$flMemERate, $objMemberInfo -> SubID, $objMemberInfo -> SubCreditLine, $objMemberInfo -> MainID, $objMemberInfo -> MainCreditLine)){
		PMA_mysql_query("ROLLBACK", $_ConnMaster);
		if($GLOBALS["errormessage"] == "")$Err_Message = $_strWagerInsert["NotOverCredit"];
		$Err_Title = $_strWagerInsert["BetError"];
		$Err_HiddenMessage = "\nLine:".__LINE__.",\nPage:".__FILE__;
		include("wager_error.php");
	}
}

//取得最新號碼賠率資料
$arrGDate = getWagerArrayData($intLID, $intLType, $intGID, $intBT, $intNum, $intOddsID, $flOdds, $_data["ChoiceNumber"]);

if($arrGDate["isError"]){
	PMA_mysql_query("ROLLBACK", $_ConnMaster);
	$Err_Message = $_strWagerInsert[$arrGDate["Err_Message"]];
	include("wager_error.php");
}elseif($arrGDate["isMessage"]){
	PMA_mysql_query("ROLLBACK", $_ConnMaster);
	$Err_Message = $_strWagerInsert[$arrGDate["Message"]];
	if($arrGDate["Message"] == "OddsChange")$isGoBack = true;
	include("wager_error.php");
}
//特碼 46用
$arrGDate["Bet_Type"] = $intBT;

$flOdds = floatval($arrGDate["Odds"]) + $flCommOddsPlus;
$flOddsAS = floatval($arrGDate["Odds"]); //自動向上補貨用賠率

$intApointNum = $_arrGLineNumToApointNum[$intLID][$intBT][$intNum];
if($intApointNum == null)$intApointNum = 0;
//加進分盤資料
include_once(__Common_Path."/gambletype/GambleType1_".$intLID.".inc.php");
$flGTAllOdds = $_arrGambleTypeAllOdds[$arrGDate["Bet_Type"]][$intApointNum];
$flOddsAS += $_arrGambleType[$intBT][$intApointNum];

include_once(__Common_Path."/gambletype/GambleType".$objMemberInfo -> GambleType."_".$intLID.".inc.php");

//下注賠率額外處理
$flOdds += $_arrGambleType[$intBT][$intApointNum];

if($intLType == 2 && $intBT == 83){
	$intDenominator = sizeof($arrChoiceNumber[0])*sizeof($arrChoiceNumber[1])*sizeof($arrChoiceNumber[2]);
	if($intDenominator == 0){
		$Err_Title = $_strWagerInsert["BetError"];
		$Err_Message = $_strWagerInsert["SelectNumberErr"];
		$Err_HiddenMessage = "\nDenominator:".$intDenominator."\nStNumber:".print_r($arrChoiceNumber, true)."\nLine:".__LINE__.",\nPage:".__FILE__;
		include("wager_error.php");
	}
	$flOdds = floor($flOdds*10000 / $intDenominator)/10;
	$flOddsAS = floor($flOddsAS*10000 / $intDenominator)/10;

}else{
	$flOdds = ConvertOddsPlus($intLType, $intBT, $flOdds);
	$flOddsAS = ConvertOddsPlus($intLType, $intBT, $flOddsAS);
}


$strWagerConditions = getWagerConditions($intLType, $arrGDate["Bet_Type"], $arrGDate["Number"], $flOdds, $arrGDate["SerialNo"], 0, $arrChoiceNumber, 0);
$strWagerConditionsAS = getWagerConditions($intLType, $arrGDate["Bet_Type"], $arrGDate["Number"], $flOddsAS, $arrGDate["SerialNo"], 0, $arrChoiceNumber, 0);

//組合陣列 for bet_BetListContent 用
$arrWCont["GameDate_x"] = $arrGDate["GameDate"];
$arrWCont["Content_x"] = $strWagerConditions;
$strCheckKey = str_replace("0.", ($_data["CheckKey2"] + 1)."-", $_data["CheckKey1"]);
$arrWCont["checkkey_x"] = $strCheckKey;
$arrWCont["GambleType"] = $objMemberInfo -> GambleType;
$arrWCont["MemAccount_x"] = $objMemberInfo -> Account;
$arrWCont["isBlack"] = $objMemberInfo -> isBlack;
$arrWCont["SuppleID_x"] = $intSuppleWagerID."";

$flMemPayOff = ($intStakeMoney*($flOdds - 1));
//組合陣列 for bet_BetList 用
$arrWList["LottoID"] = $arrGDate["LottoID"];
$arrWList["LType"] = $intLType;
$arrWList["Bet_Type"] = $arrGDate["Bet_Type"];
$arrWList["GambleID"] = $arrGDate["GambleID"];
$arrWList["Number"] = $arrGDate["Number"];
$arrWList["OddsID"] = $arrGDate["OddsID"];
$arrWList["Odds"] = $flOdds;
$arrWList["MemID"] = $objMemberInfo -> ID;
$arrWList["MemExchangeRate"] = $flMemERate;
$arrWList["MemCurrency"] = $objMemberInfo -> ERID;
$arrWList["ExRecordID"] = $objMemberInfo -> ExRecordID;
$arrWList["MemStake"] = $intStakeMoney;
$arrWList["MemPayOff"] = $flMemPayOff;
$arrWList["MemCommission"] = 1 - ($arrComm[1] / 100);
$arrWList["SubID"] = $objMemberInfo -> SubID;
$arrWList["SubCommission"] = 1 - ($arrComm[2] / 100);
$arrWList["SubRate"] = $objMemberInfo -> SubScale;
$arrWList["MainID"] = $objMemberInfo -> MainID;
$arrWList["MainCommission"] = 1 - ($arrComm[3] / 100);
$arrWList["MainRate"] = $objMemberInfo -> MainScale;
$arrWList["StockID"] = $objMemberInfo -> StockID;
$arrWList["StockCommission"] = 1 - ($arrComm[4] / 100);
$arrWList["StockRate"] = $objMemberInfo -> StockScale;
$arrWList["DirectorID"] = $objMemberInfo -> DirectorID;
$arrWList["DirectorCommission"] = 1 - ($arrComm[5] / 100);
$arrWList["DirectorRate"] = $objMemberInfo -> DirectorScale;
$arrWList["Layer6ID"] = $objMemberInfo -> Layer6ID;
$arrWList["Layer6Commission"] = 1 - ($arrComm[6] / 100);
$arrWList["Layer6Rate"] = $objMemberInfo -> Layer6Scale;
$arrWList["PayupDate_x"] = $arrGDate["PayupDate"];
if($objMemberInfo -> WagerType >= 2)$arrWList["WagerType"] = $objMemberInfo -> WagerType;

//寫入注單
$arrBetData = InsertWagerToDB($arrWCont, $arrWList);
if($arrBetData["isError"]){
	PMA_mysql_query("ROLLBACK", $_ConnMaster);
	$Err_Message = $arrBetData["ErrorMessage"]."1";
	$Err_HiddenMessage = $arrBetData["ErrorHiddenMessage"];
	include("wager_error.php");
}

$arrRealToday = array();
switch($objMemberInfo -> WagerType){
	case 0:
		$arrRealToday[$objMemberInfo -> SubID] = array("W" => 1, "S" => $arrWList["MemStake"], "P" => $arrWList["MemPayOff"], 
									"C" => $arrWList["MemStake"]*$arrWList["MemCommission"]*$flMemERate*(1 - $objMemberInfo -> SubScale), 
									"RS" => $arrWList["MemStake"]*$flMemERate*(1 - $objMemberInfo -> SubScale), 
									"RP" => $arrWList["MemPayOff"]*$flMemERate*(1 - $objMemberInfo -> SubScale));
	case 2:
		$arrRealToday[$objMemberInfo -> MainID] = array("W" => 1, "S" => $arrWList["MemStake"], "P" => $arrWList["MemPayOff"], 
								"C" => $arrWList["MemStake"]*$arrWList["SubCommission"]*$flMemERate*($objMemberInfo -> SubScale - $objMemberInfo -> MainScale), 
								"RS" => $arrWList["MemStake"]*$flMemERate*($objMemberInfo -> SubScale - $objMemberInfo -> MainScale), 
								"RP" => $arrWList["MemPayOff"]*$flMemERate*($objMemberInfo -> SubScale - $objMemberInfo -> MainScale));
	case 3:
		$arrRealToday[$objMemberInfo -> StockID] = array("W" => 1, "S" => $arrWList["MemStake"], "P" => $arrWList["MemPayOff"], 
								"C" => $arrWList["MemStake"]*$arrWList["MainCommission"]*$flMemERate*($objMemberInfo -> MainScale - $objMemberInfo -> StockScale), 
								"RS" => $arrWList["MemStake"]*$flMemERate*($objMemberInfo -> MainScale - $objMemberInfo -> StockScale), 
								"RP" => $arrWList["MemPayOff"]*$flMemERate*($objMemberInfo -> MainScale - $objMemberInfo -> StockScale));
	case 4:
		$arrRealToday[$objMemberInfo -> DirectorID] = array("W" => 1, "S" => $arrWList["MemStake"], "P" => $arrWList["MemPayOff"], 
								"C" => $arrWList["MemStake"]*$arrWList["StockCommission"]*$flMemERate*($objMemberInfo -> StockScale - $objMemberInfo -> DirectorScale), 
								"RS" => $arrWList["MemStake"]*$flMemERate*($objMemberInfo -> StockScale - $objMemberInfo -> DirectorScale), 
								"RP" => $arrWList["MemPayOff"]*$flMemERate*($objMemberInfo -> StockScale - $objMemberInfo -> DirectorScale));
	case 5:
		$arrRealToday[$objMemberInfo -> Layer6ID] = array("W" => 1, "S" => $arrWList["MemStake"], "P" => $arrWList["MemPayOff"], 
								"C" => $arrWList["MemStake"]*$arrWList["DirectorCommission"]*$flMemERate*($objMemberInfo -> DirectorScale - $objMemberInfo -> Layer6Scale), 
								"RS" => $arrWList["MemStake"]*$flMemERate*($objMemberInfo -> DirectorScale - $objMemberInfo -> Layer6Scale), 
								"RP" => $arrWList["MemPayOff"]*$flMemERate*($objMemberInfo -> DirectorScale - $objMemberInfo -> Layer6Scale));
	case 6:
		break;
}
if($objMemberInfo -> WagerType > 0){
	$arrWagerTypeUID = array(2 => $objMemberInfo -> SubID, 3 => $objMemberInfo -> MainID, 4 => $objMemberInfo -> StockID, 5 => $objMemberInfo -> DirectorID, 5 => $objMemberInfo -> Layer6ID);
	$arrRealToday[$arrWagerTypeUID[$objMemberInfo -> WagerType]] = array("SW" => 1, "SS" => $arrWList["MemStake"], "SP" => $arrWList["MemPayOff"], 
								"SC" => $arrWList["MemStake"]*$arrWList["MemCommission"]);
}

$flPlusMemStake = 0;
$flPlusMemPayOff = 0;
//自動補貨
if($isAutoSupple){
	$arrCommission = array();
	if(sizeof($arrAutoSuppleGroup) > 0){
		//找出代理商、總代理、股東、總監 A盤退水
		foreach($objMemberInfo -> arrCommissionA as $intUID => $arrC){
			$arrCommission[$intUID] = 1 - ($arrC[$intLID][$intBT] / 100);
		}
	}
	//print_r($arrAutoSuppleGroup);
	//print_r($objMemberInfo);
	$arrPlusStake = array("Stake" => 0, "RealStake" => 0, "PayOff" => 0, "RealPayOff" => 0);
	$arrGroupAcc = array(2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0);
	foreach($arrAutoSuppleGroup as $intUID => $intGroup){
		$arrWListTmp = $arrWList;
		$arrWListTmp["Odds"] = $flOddsAS;
		$arrWListTmp["MemExchangeRate"] = 1;
		$arrWListTmp["MemCurrency"] = 1;
		$arrWListTmp["MemStake"] = $arrAutoSuppleGold[$intUID];
		$arrWListTmp["MemPayOff"] = $arrAutoSuppleGold[$intUID]*($arrWListTmp["Odds"] - 1);
		$arrWListTmp["WagerType"] = $intGroup;
		//print "@@@".$intUID."=>".$arrWListTmp["WagerType"]."QQQ";

		$arrWContTmp = $arrWCont;
		$strCheckKey = str_replace("0.", ($_data["CheckKey2"] + $intGroup)."-", $_data["CheckKey1"]);
		$arrWContTmp["checkkey_x"] = $strCheckKey;
		$arrWContTmp["Content_x"] = $strWagerConditionsAS." (Auto)";

		$arrWListTmp["Layer6Commission"] = $arrCommission[$objMemberInfo -> Layer6ID];
		$arrWListTmp["DirectorCommission"] = $arrCommission[$objMemberInfo -> DirectorID];
		$arrWListTmp["StockCommission"] = $arrCommission[$objMemberInfo -> StockID];
		$arrWListTmp["MainCommission"] = $arrCommission[$objMemberInfo -> MainID];
		$arrWListTmp["SubCommission"] = $arrCommission[$objMemberInfo -> SubID];

		$arrLayerScale = $objMemberInfo -> LayerScale[$intGroup];
		$arrWListTmp["SubRate"] = $arrLayerScale[2];
		$arrWListTmp["MainRate"] = $arrLayerScale[3];
		$arrWListTmp["StockRate"] = $arrLayerScale[4];
		$arrWListTmp["DirectorRate"] = $arrLayerScale[5];
		$arrWListTmp["Layer6Rate"] = $arrLayerScale[6];
		switch($intGroup){
			case 6:
				$arrWListTmp["DirectorID"] = $intUID;
				$arrWListTmp["DirectorCommission"] = $arrCommission[$intUID];
			case 5:
				$arrWListTmp["StockID"] = $intUID;
				$arrWListTmp["StockCommission"] = $arrCommission[$intUID];
			case 4:
				$arrWListTmp["MainID"] = $intUID;
				$arrWListTmp["MainCommission"] = $arrCommission[$intUID];
			case 3:
				$arrWListTmp["SubID"] = $intUID;
				$arrWListTmp["SubCommission"] = $arrCommission[$intUID];
			case 2:
				$arrWListTmp["MemID"] = $intUID;
				$arrWListTmp["MemCommission"] = $arrCommission[$intUID];
				break;
		}
		$arrWContTmp["MemAccount_x"] = $objMemberInfo -> LayerAcc[$intGroup];

		switch($intGroup){
			case 2:
				$arrRealToday[$objMemberInfo -> MainID]["W"] += 1;
				$arrRealToday[$objMemberInfo -> MainID]["S"] += $arrWListTmp["MemStake"];
				$arrRealToday[$objMemberInfo -> MainID]["P"] += $arrWListTmp["MemPayOff"];
				$arrRealToday[$objMemberInfo -> MainID]["C"] += $arrWListTmp["MemStake"]*$arrWListTmp["SubCommission"]*($arrLayerScale[2] - $arrLayerScale[3]);
				$arrRealToday[$objMemberInfo -> MainID]["RS"] += $arrWListTmp["MemStake"]*($arrLayerScale[2] - $arrLayerScale[3]);
				$arrRealToday[$objMemberInfo -> MainID]["RP"] += $arrWListTmp["MemPayOff"]*($arrLayerScale[2] - $arrLayerScale[3]);
			case 3:
				$arrRealToday[$objMemberInfo -> StockID]["W"] += 1;
				$arrRealToday[$objMemberInfo -> StockID]["S"] += $arrWListTmp["MemStake"];
				$arrRealToday[$objMemberInfo -> StockID]["P"] += $arrWListTmp["MemPayOff"];
				$arrRealToday[$objMemberInfo -> StockID]["C"] += $arrWListTmp["MemStake"]*$arrWListTmp["MainCommission"]*($arrLayerScale[3] - $arrLayerScale[4]);
				$arrRealToday[$objMemberInfo -> StockID]["RS"] += $arrWListTmp["MemStake"]*($arrLayerScale[3] - $arrLayerScale[4]);
				$arrRealToday[$objMemberInfo -> StockID]["RP"] += $arrWListTmp["MemPayOff"]*($arrLayerScale[3] - $arrLayerScale[4]);
			case 4:
				$arrRealToday[$objMemberInfo -> DirectorID]["W"] += 1;
				$arrRealToday[$objMemberInfo -> DirectorID]["S"] += $arrWListTmp["MemStake"];
				$arrRealToday[$objMemberInfo -> DirectorID]["P"] += $arrWListTmp["MemPayOff"];
				$arrRealToday[$objMemberInfo -> DirectorID]["C"] += $arrWListTmp["MemStake"]*$arrWListTmp["StockCommission"]*($arrLayerScale[4] - $arrLayerScale[5]);
				$arrRealToday[$objMemberInfo -> DirectorID]["RS"] += $arrWListTmp["MemStake"]*($arrLayerScale[4] - $arrLayerScale[5]);
				$arrRealToday[$objMemberInfo -> DirectorID]["RP"] += $arrWListTmp["MemPayOff"]*($arrLayerScale[4] - $arrLayerScale[5]);
			case 5:
				$arrRealToday[$objMemberInfo -> Layer6ID]["W"] += 1;
				$arrRealToday[$objMemberInfo -> Layer6ID]["S"] += $arrWListTmp["MemStake"];
				$arrRealToday[$objMemberInfo -> Layer6ID]["P"] += $arrWListTmp["MemPayOff"];
				$arrRealToday[$objMemberInfo -> Layer6ID]["C"] += $arrWListTmp["MemStake"]*$arrWListTmp["StockCommission"]*($arrLayerScale[5] - $arrLayerScale[6]);
				$arrRealToday[$objMemberInfo -> Layer6ID]["RS"] += $arrWListTmp["MemStake"]*($arrLayerScale[5] - $arrLayerScale[6]);
				$arrRealToday[$objMemberInfo -> Layer6ID]["RP"] += $arrWListTmp["MemPayOff"]*($arrLayerScale[5] - $arrLayerScale[6]);
			case 6:
				break;
		}
		$arrRealToday[$intUID]["SW"] = 1;
		$arrRealToday[$intUID]["SS"] = $arrWListTmp["MemStake"];
		$arrRealToday[$intUID]["SP"] = $arrWListTmp["MemPayOff"];
		$arrRealToday[$intUID]["SC"] = $arrWListTmp["MemCommission"]*$arrWListTmp["MemStake"];
		
		$arrPlusStake["Stake"] +=  $arrWListTmp["MemStake"];
		$arrPlusStake["RealStake"] +=  $arrWListTmp["MemStake"]*$arrWListTmp["DirectorRate"];
		$arrPlusStake["PayOff"] +=  $arrWListTmp["MemPayOff"];
		$arrPlusStake["RealPayOff"] +=  $arrWListTmp["MemPayOff"]*$arrWListTmp["DirectorRate"];
		//print ($arrWListTmp["MemStake"]*$arrWListTmp["DirectorRate"])."<br />\n";

		//寫入自動補貨注單
		$arrAutoSuppleBetData = InsertWagerToDB($arrWContTmp, $arrWListTmp);
		if($arrAutoSuppleBetData["isError"]){
			PMA_mysql_query("ROLLBACK", $_ConnMaster);
			$Err_Message = $arrAutoSuppleBetData["ErrorMessage"]."1";
			$Err_HiddenMessage = $arrAutoSuppleBetData["ErrorHiddenMessage"];
			include("wager_error.php");
		}
	}
}

//押碼跳動
if($intLType == 2 && $intBT >= 69 && $intBT <= 77){
	$intNumNo = sizeof($arrChoiceNumber);
	$intMemStakeTmp = $arrWList["MemStake"] / $intNumNo;
	$arrPlusStake["Stake"] =  $arrPlusStake["Stake"] / $intNumNo;
	$arrPlusStake["RealStake"] =  $arrPlusStake["RealStake"] / $intNumNo;
	$arrPlusStake["PayOff"] =  $arrPlusStake["PayOff"] / $intNumNo;
	$arrPlusStake["RealPayOff"] =  $arrPlusStake["RealPayOff"] / $intNumNo;

	foreach($arrChoiceNumber as $k => $intNumTmp){
		$arrGDateTmp = getWagerArrayData($intLID, $intLType, $intGID, $intBT, $intNumTmp, $intOddsID, $flOdds, $intNumTmp);
		$arrBT[$k] = $intBT;
		$arrOddsID[$k] = $arrGDateTmp["OddsID"];
		$arrOdds[$k] = $arrGDateTmp["Odds"];
		$intMemPayOffTmp = $intMemStakeTmp*($arrGDateTmp["Odds"] - 1);

		if($arrGDateTmp["isError"]){
			PMA_mysql_query("ROLLBACK", $_ConnMaster);
			$Err_Message = $_strWagerInsert[$arrGDate["Err_Message"]]."2";
			include("wager_error.php");
		}
		$arrJumpData = WagerJump($arrGDateTmp, $intMemStakeTmp, $intMemPayOffTmp, $_arrBetParam[$intBT][$intAN], $flGTAllOdds, $arrWList["MemExchangeRate"]*$arrWList["DirectorRate"], $arrWList["DirectorCommission"], $arrPlusStake);
		if($arrJumpData["isError"]){
			PMA_mysql_query("ROLLBACK", $_ConnMaster);
			$Err_Message = ($_strWagerInsert[$GLOBALS["errormessage"]] != "")?$_strWagerInsert[$GLOBALS["errormessage"]]:$GLOBALS["errormessage"];
			$Err_HiddenMessage = $GLOBALS["errorhidden"]."3";
			include("wager_error.php");
		}
	}
	/*$arrBetParlaysData = InsertParlaysThroughToDB($arrBetData["BetID"], $intGID, $arrBT, $arrChoiceNumber, $arrOddsID, $arrOdds);
	if($arrBetParlaysData["isError"]){
		PMA_mysql_query("ROLLBACK", $_ConnMaster);
		$Err_Message = $_strWagerInsert[$arrBetParlaysData["ErrorMessage"]]."4";
		$Err_HiddenMessage = $arrBetParlaysData["ErrorMessage"].$arrBetParlaysData["ErrorHiddenMessage"];
		include("wager_error.php");
	}*/

	//Steve 要的資料
	$arrTmp = array();
	foreach($arrChoiceNumGroup as $intNum){
		$arrTmp[$intBT][$intNum][0] = array("W" => 1, "S" => $arrWList["MemStake"], "P" => $arrWList["MemPayOff"], 
								"C" => $arrWList["MemStake"]*$arrWList["DirectorCommission"]*$flMemERate*$objMemberInfo -> DirectorScale, 
								"RS" => $arrWList["MemStake"]*$flMemERate*$objMemberInfo -> DirectorScale, 
								"RP" => $arrWList["MemPayOff"]*$flMemERate*$objMemberInfo -> DirectorScale);
	}
	if(!setCountWagerForAllLayers($intLID, $intGID, $arrTmp)){
		PMA_mysql_query("ROLLBACK", $_ConnMaster);
		$Err_Message = ($_strWagerInsert[$GLOBALS["errormessage"]] != "")?$_strWagerInsert[$GLOBALS["errormessage"]]:$GLOBALS["errormessage"];
		$Err_HiddenMessage = $GLOBALS["errorhidden"]."66";
		include("wager_error.php");
	}

}else{
	$arrJumpData = WagerJump($arrGDate, $arrWList["MemStake"], $arrWList["MemPayOff"], $_arrBetParam[$intBT][$intAN], $flGTAllOdds, $arrWList["MemExchangeRate"]*$arrWList["DirectorRate"], $arrWList["DirectorCommission"], $arrPlusStake);
	if($arrJumpData["isError"]){
		PMA_mysql_query("ROLLBACK", $_ConnMaster);
		$Err_Message = ($_strWagerInsert[$GLOBALS["errormessage"]] != "")?$_strWagerInsert[$GLOBALS["errormessage"]]:$GLOBALS["errormessage"];
		$Err_HiddenMessage = $GLOBALS["errorhidden"]."5";
		include("wager_error.php");
	}

	$arrTmp = array();
	$arrTmp[$intBT][$intNum] = $arrRealToday;
	if(!setCountWagerForAllLayers($intLID, $intGID, $arrTmp)){
		PMA_mysql_query("ROLLBACK", $_ConnMaster);
		$Err_Message = ($_strWagerInsert[$GLOBALS["errormessage"]] != "")?$_strWagerInsert[$GLOBALS["errormessage"]]:$GLOBALS["errormessage"];
		$Err_HiddenMessage = $GLOBALS["errorhidden"]."6";
		include("wager_error.php");
	}
} //if($intBT >= 69 && $intBT <= 77){

$arrSucc[0]["BetID"] = $arrBetData["BetID"];
$arrSucc[0]["StakeMoneyValue"] = $intStakeMoney;
$arrSucc[0]["WagerMessage"] = WagerFormTrans($arrGDate["LottoID"], $arrGDate["Bet_Type"], $strWagerConditions);
$arrSucc[0]["PayOffValue"] = $flMemPayOff;

//產生累積注額陣列
if(!getWagerArrayGold($objMemberInfo -> ID)){
	PMA_mysql_query("ROLLBACK", $_ConnMaster);
	$Err_Message = ($_strWagerInsert[$GLOBALS["errormessage"]] != "")?$_strWagerInsert[$GLOBALS["errormessage"]]:$GLOBALS["errormessage"];
	$Err_HiddenMessage = $GLOBALS["errorhidden"]."6";
	include("wager_error.php");
}

//交易完成
PMA_mysql_query("COMMIT", $_ConnMaster);
AddData_Log($objMemberInfo -> ID,"下注成功 ", $arrBetData["LogData"]);
$Err_Message = "Success!!";
@mysql_close($$_Conn);
include("wager_success.php");
?>